<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

</head>
<body>
    <script src="./javascripts/check_login.js"></script>
    <div class="root">
        <h1></h1>
        <span></span>
    </div>
    <script>
        (function () {
            // 获取查询字符串（包括?）
            let queryString = window.location.search;
    
            // 移除开头的?
            if (queryString.indexOf("?") === 0) {
                queryString = queryString.substring(1);
            }
    
            // 使用split方法分割字符串为键值对数组
            let params = queryString.split("&");
    
            // 创建一个对象来存储参数
            let paramObj = {};
    
            // 遍历数组并将键值对存储到对象中
            for (let i = 0; i < params.length; i++) {
                var pair = params[i].split("=");
                paramObj[pair[0]] = pair[1];
            }
    
            // 现在你可以通过paramObj.id来获取id的值
            let id = paramObj.id;
    
            console.log(id); // 输出: 1
    
            const xhr = new XMLHttpRequest();
            xhr.onload = function () {
                if (xhr.status == 200) {
                    let res_data = JSON.parse(xhr.responseText);
                    document.querySelector('.root h1').innerText = res_data.name;
                    document.querySelector('.root span').innerText = res_data.content;
                    console.log(res_data);
                }
            };
            let data = {jwt: jwt, id: id};
            xhr.open('POST', '/dynamic/show_one_dynamic', true);
            xhr.setRequestHeader('Content-Type', 'application/json');
            xhr.send(JSON.stringify(data));
        })();
    </script>
</body>
</html>